package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.utils.SerializeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

import java.util.LinkedList;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private JedisPool jedisPool;
    @RequestMapping("/getMenu")
    public LinkedList<Menu> getMenu(){
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username = user.getUsername();
        byte[] bytes = jedisPool.getResource().get(username.getBytes());
        LinkedList<Menu> unserialize = (LinkedList<Menu>) SerializeUtil.unserialize(bytes);
        return unserialize;
    }
}
